//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.tuliu.appupdate.updatelib;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Parcel;
import android.os.Parcelable;

/**
 * @author liaoyong
 * @desc 下载信息model
 * @date 2016/4/11 13:57
 */
class DownloadInfo implements Parcelable {
    String title;
    String downloadUrl;
    String file;
    String packageName;
    AppInfo updateInfo;
    boolean showNotification = true;
    boolean autoInstall = false;
    boolean autoInstallAndOpen = false;
    public static final Creator<DownloadInfo> CREATOR = new Creator() {
        public DownloadInfo createFromParcel(Parcel source) {
            return new DownloadInfo(source);
        }

        public DownloadInfo[] newArray(int size) {
            return new DownloadInfo[size];
        }
    };

    DownloadInfo() {
    }

    DownloadInfo(Context context, AppInfo info) {
        this.packageName = info.packageName;
        PackageManager pm = context.getPackageManager();

        try {
            ApplicationInfo e = pm.getApplicationInfo(this.packageName, 0);
            this.title = (String)pm.getApplicationLabel(e);
        } catch (NameNotFoundException var5) {
            ;
        }

        this.downloadUrl = info.downloadUrl;
        this.downloadUrl = Utils.appendParams(this.downloadUrl, context);
        this.file = Utils.getUpdateFile(context, this.downloadUrl, info.packageName);
        this.updateInfo = info;
    }

    static DownloadInfo createAppStoreDownloadInfo(Context context, AppInfo updateInfo) {
        DownloadInfo info = new DownloadInfo(context, updateInfo);
        info.downloadUrl = updateInfo.appStoreDownloadUrl;
        info.title = RHelper.getString(context, "appstore_title");
        info.packageName = "com.qihoo.appstore";
        info.file = Utils.getUpdateFile(context, info.downloadUrl, info.packageName);
        return info;
    }

    DownloadInfo(Parcel source) {
        this.title = source.readString();
        this.downloadUrl = source.readString();
        this.file = source.readString();
        this.packageName = source.readString();
        this.showNotification = source.readInt() == 1;
        this.autoInstall = source.readInt() == 1;
        this.autoInstallAndOpen = source.readInt() == 1;
        this.updateInfo = (AppInfo)source.readParcelable(AppInfo.class.getClassLoader());
    }

    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.title);
        dest.writeString(this.downloadUrl);
        dest.writeString(this.file);
        dest.writeString(this.packageName);
        dest.writeInt(this.showNotification?1:0);
        dest.writeInt(this.autoInstall?1:0);
        dest.writeInt(this.autoInstallAndOpen?1:0);
        dest.writeParcelable(this.updateInfo, flags);
    }

    public int describeContents() {
        return 0;
    }
}
